<?php

namespace Index\Controller;

class CateController extends CommonController {

    private $Cate;
    private $cate_id;

    public function __construct(){
        parent::__construct();
        $this->Cate = new \Common\Model\BookCateModel();
        $this->cate_id = I('request.cate_id');
        if(empty($this->cate_id) || !is_numeric($this->cate_id)){
            $this->error("该页面不存在");exit;
        }
    }

    //章节列表
    public function index(){
        $this->limit = 20;
        $Book = new \Common\Model\BookModel();
        $cates = $this->Cate->getCate($this->cate_id);
        $where = "`cate_id` = '{$this->cate_id}'";

        //点击榜单
        $hotBooks = $Book->getList($where, $order = 'brow_num DESC',0,30,$fields='');
        if(empty($hotBooks['lists'])){
            $this->error("该页面不存在");exit;
        }
        $this->assign('hotBooks',$hotBooks['lists']);
        $this->_pageTitle = $cates['name'].'最新更新_'.C('SYS_NAME');
        $this->_pageKeywords = '玄幻小说,奇幻小说,在线阅读,玄幻奇幻小说,免费小说';
        $this->_pageDescription = C('SYS_NAME').$cates['name'].'频道，汇集各类精品小说，为读者提供包括玄幻奇幻小说,武侠小说,网游小说,都市小说,历史军事小说等内容"';
        //推荐的八本书
        $ids = str_replace(':',',',$cates['tj_book']);
        $tjBooks = $Book->getList("book_id IN({$ids})",'',0,8);
        $this->assign('tjBooks',$tjBooks['lists']);

        //最新更新
        $Article = D('Common/BookArticle');
        $updateBooks = $Article->getCateUpdate($this->cate_id);
        //p($updateBooks);exit;
        $this->assign('updateBook',$updateBooks);
        $this->assign('cate',$cates);
        $this->display('Index/cate');
    }



}